<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveRecord::DynamicMatchers::Method</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActiveRecord::DynamicMatchers::Method 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activerecord/lib/active_record/dynamic_matchers_rb.html">activerecord/lib/active_record/dynamic_matchers.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-i-body">body</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-i-define">define</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>M</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-c-match">match</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-c-pattern">pattern</a>,
              </li>
            
              
              <li>
                <a href="Method.html#method-c-prefix">prefix</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-c-suffix">suffix</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>V</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Method.html#method-i-valid-3F">valid?</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>matchers</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>attribute_names</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>model</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>name</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-match">
            
              <b>match</b>(model, name)
            
            <a href="Method.html#method-c-match" name="method-c-match" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-match_source')" id="l_method-c-match_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L32" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-match_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">match</span>(<span class="ruby-identifier">model</span>, <span class="ruby-identifier">name</span>)
  <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">matchers</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">pattern</span> }
  <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">model</span>, <span class="ruby-identifier">name</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">klass</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(model, name)
            
            <a href="Method.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L52" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 52</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">model</span>, <span class="ruby-identifier">name</span>)
  <span class="ruby-ivar">@model</span>           = <span class="ruby-identifier">model</span>
  <span class="ruby-ivar">@name</span>            = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-ivar">@attribute_names</span> = <span class="ruby-ivar">@name</span>.<span class="ruby-identifier">match</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">pattern</span>)[<span class="ruby-number">1</span>].<span class="ruby-identifier">split</span>(<span class="ruby-string">'_and_'</span>)
  <span class="ruby-ivar">@attribute_names</span>.<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">n</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@model</span>.<span class="ruby-identifier">attribute_aliases</span>[<span class="ruby-identifier">n</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">n</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-pattern">
            
              <b>pattern</b>()
            
            <a href="Method.html#method-c-pattern" name="method-c-pattern" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-pattern_source')" id="l_method-c-pattern_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L37" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-pattern_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 37</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">pattern</span>
  <span class="ruby-node">/^#{prefix}_([_a-zA-Z]\w*)#{suffix}$/</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-prefix">
            
              <b>prefix</b>()
            
            <a href="Method.html#method-c-prefix" name="method-c-prefix" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-prefix_source')" id="l_method-c-prefix_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L41" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-prefix_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 41</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">prefix</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-suffix">
            
              <b>suffix</b>()
            
            <a href="Method.html#method-c-suffix" name="method-c-suffix" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-suffix_source')" id="l_method-c-suffix_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L45" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-suffix_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 45</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">suffix</span>
  <span class="ruby-string">''</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-body">
            
              <b>body</b>()
            
            <a href="Method.html#method-i-body" name="method-i-body" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-body_source')" id="l_method-i-body_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L71" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-body_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">body</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-define">
            
              <b>define</b>()
            
            <a href="Method.html#method-i-define" name="method-i-define" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-define_source')" id="l_method-i-define_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L63" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-define_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 63</span>
      <span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">define</span>
        <span class="ruby-identifier">model</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-string">&quot;          def self.#{name}(#{signature})
            #{body}
          end
&quot;</span>, <span class="ruby-keyword">__FILE__</span>, <span class="ruby-keyword">__LINE__</span> <span class="ruby-operator">+</span> <span class="ruby-number">1</span>
      <span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-valid-3F">
            
              <b>valid?</b>()
            
            <a href="Method.html#method-i-valid-3F" name="method-i-valid-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-valid-3F_source')" id="l_method-i-valid-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a44a5e4bbd0c1429a052444f4ce715d5360c1a0b/activerecord/lib/active_record/dynamic_matchers.rb#L59" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-valid-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activerecord/lib/active_record/dynamic_matchers.rb, line 59</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">valid?</span>
  <span class="ruby-identifier">attribute_names</span>.<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span> <span class="ruby-identifier">model</span>.<span class="ruby-identifier">columns_hash</span>[<span class="ruby-identifier">name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">model</span>.<span class="ruby-identifier">reflect_on_aggregation</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    